/*
  封装本地存储模块
*/

export const getItem = name => {
  const data = localStorage.getItem(name)
  try {
    // 防止 data 不是json格式字符串，会报错
    return JSON.parse(data)
  } catch (error) {
    // 不是 json 格式字符串就没必要进行转化
    return data
  }
}

export const setItem = (name, value) => {
  if (typeof value === 'object') {
    value = JSON.stringify(value)
  }
  localStorage.setItem(name, value)
}

export const removeItem = (name) => localStorage.removeItem(name)
